﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace TestSqlite
{
    [TestClass]
    public class TestUserInfoWithIdentity
    {
        [TestMethod]
        public void TestInsertEntity()
        {
            int rowCount = UserInfoEntity.GetAllEntities().Count;
            UserInfoEntity entity = new UserInfoEntity();
            entity.Name = "testUser";
            entity.Save();

            Assert.AreEqual(rowCount + 1, UserInfoEntity.GetAllEntities().Count);
        }

        [TestMethod]
        public void TestUpdateEntity()
        {
            UserInfoEntity entity = new UserInfoEntity();
            entity.Name = "testUser";
            entity.Save();

            entity.Name = "updatedTestUser";
            entity.Save();

            IList<UserInfoEntity> users = UserInfoEntity.SearchEntities("where Name={0}", entity.Name);
            Assert.AreEqual(true, users.Count > 0);

            entity.Name = "testUser";
            entity.Save();
        }

        [TestMethod]
        public void TestDeleteEntity()
        {           

            UserInfoEntity entity = new UserInfoEntity();
            entity.Name = "testUser";
            entity.Save();

            int rowCount = UserInfoEntity.GetAllEntities().Count;

            entity.IsDelete = true;
            entity.Save();

            Assert.AreEqual(rowCount-1, UserInfoEntity.GetAllEntities().Count);
        }
    }
}
